package calender;

import java.util.Calendar;

/**
 * Created with IntelliJ IDEA
 * Description:Calender类学习
 * User:22954
 * Date:2024-01-30
 * Time:2:32
 */
public class Test {
    public static void main(String[] args) {
        /**
         * Calender类是抽象类，不能被实例化，且构造方法为protected
         * 只能用Calender的静态方法getInstance()实例化
         */
        Calendar calendar=Calendar.getInstance();
        System.out.println(calendar);//java.util.GregorianCalendar[time=1706553214288,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+08:00",offset=28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=1,ERA=1,YEAR=2024,MONTH=0,WEEK_OF_YEAR=5,WEEK_OF_MONTH=5,DAY_OF_MONTH=30,DAY_OF_YEAR=30,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=5,AM_PM=0,HOUR=2,HOUR_OF_DAY=2,MINUTE=33,SECOND=34,MILLISECOND=288,ZONE_OFFSET=28800000,DST_OFFSET=0]
        System.out.println("year="+calendar.get(Calendar.YEAR));
        System.out.println("month="+(calendar.get(Calendar.MONTH)+1));//Calender里面的MONTH是从0开始算的
        System.out.println("day="+calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("hour="+calendar.get(Calendar.HOUR));
        System.out.println("minute="+calendar.get(Calendar.MINUTE));
        /**
         * Calender没有格式化的方法
         * 由程序员自行组合输出
         */
        System.out.println("year="+calendar.get(Calendar.YEAR)+" month="+(calendar.get(Calendar.MONTH)+1)+" day="+calendar.get(Calendar.DAY_OF_MONTH));
    }
}
